package com.shine.app.ui;

import android.os.AsyncTask;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.shine.app.R;
import com.shine.app.bean.GolferBean;
import com.shine.app.bean.UserBean;
import com.shine.app.bean.responses.ViewMyGolfResponse;

public class SearchTeeTimeSlideviewActivity extends RangeBarActivity {

	protected TextView userNameTextView;
	protected TextView logOutTextView;
	protected RelativeLayout userLayout;

	protected LinearLayout menu;
	protected LinearLayout content;
	protected DrawerLayout drawerLayout;

	protected TableRow menu_bookingTableRow;
	protected TableRow menu_favoriteTableRow;
	protected TableRow menu_reviewTableRow;
	protected TextView bookingNumberTextView;
	protected TextView favoriteNumberTextView;
	protected TextView reviewNumberTextView;

	protected TableRow menu_editProfileTableRow;
	protected TableRow menu_socalTableRow;
	protected TableRow menu_passWordTableRow;

	protected TableRow menu_aboutTableRow;
	protected TableRow menu_contactTableRow;
	protected TableRow menu_privacyTableRow;
	protected TableRow menu_termTableRow;
	protected TableRow menu_cancelTeeTimeTableRow;
	protected View menu_cancelTeeTimeLine;

	protected ProgressBar progressBar;
	protected LinearLayout privateLayout;
	protected Button slideview_button;

	protected void initSlidMenu() {
		logOutTextView = (TextView) this.findViewById(R.id.menu_sign);
		userNameTextView = (TextView) this.findViewById(R.id.username);
		userLayout = (RelativeLayout) this.findViewById(R.id.menu_user);

		menu = (LinearLayout) this.findViewById(R.id.menu);
		content = (LinearLayout) this.findViewById(R.id.content);
		drawerLayout = (DrawerLayout) this.findViewById(R.id.main_layout);
		menu_bookingTableRow = (TableRow) this.findViewById(R.id.menu_booking);
		menu_favoriteTableRow = (TableRow) this
				.findViewById(R.id.menu_favorite);
		menu_reviewTableRow = (TableRow) this.findViewById(R.id.menu_review);
		bookingNumberTextView = (TextView) this
				.findViewById(R.id.menu_booking_number);
		favoriteNumberTextView = (TextView) this
				.findViewById(R.id.menu_favorite_number);
		reviewNumberTextView = (TextView) this
				.findViewById(R.id.menu_review_number);

		menu_editProfileTableRow = (TableRow) this
				.findViewById(R.id.menu_editprofile);
		menu_socalTableRow = (TableRow) this.findViewById(R.id.menu_social);
		menu_passWordTableRow = (TableRow) this
				.findViewById(R.id.menu_password);

		menu_aboutTableRow = (TableRow) this.findViewById(R.id.menu_about);
		menu_contactTableRow = (TableRow) this.findViewById(R.id.menu_contact);
		menu_privacyTableRow = (TableRow) this.findViewById(R.id.menu_privacy);
		menu_termTableRow = (TableRow) this.findViewById(R.id.menu_term);
		menu_cancelTeeTimeTableRow = (TableRow) this
				.findViewById(R.id.menu_cancel_teetime);
		menu_cancelTeeTimeLine = this
				.findViewById(R.id.menu_cancel_teetime_line);

		progressBar = (ProgressBar) this.findViewById(R.id.progressBar);
		privateLayout = (LinearLayout) this.findViewById(R.id.privateLayout);
		slideview_button = (Button) this.findViewById(R.id.slideview_button);
		progressBar.setVisibility(View.GONE);
	}

	protected void initSlideviewData() {
		if (appContext.isLogin()) {
			UserBean user = appContext.getLoginInfo().getUser();
			String golferId = user.getGolferId();
			GolfAsyncTask golfAsyncTask = new GolfAsyncTask();
			golfAsyncTask.execute(golferId);
		}
	}

	public class GolfAsyncTask extends
			AsyncTask<Object, Integer, ViewMyGolfResponse> {
		private String golferId;

		@Override
		protected ViewMyGolfResponse doInBackground(Object... params) {
			ViewMyGolfResponse response = null;
			golferId = (String) params[0];
			response = appContext.golfer(golferId);
			return response;
		}

		@Override
		protected void onPostExecute(ViewMyGolfResponse result) {
			super.onPostExecute(result);
			if (result != null && (!result.isHasError())) {
				GolferBean golferBean = result.getData();
				bookingNumberTextView.setText(String.valueOf(golferBean
						.getFutureReservationCount()));
				favoriteNumberTextView.setText(String.valueOf(golferBean
						.getCourseCount()));
				reviewNumberTextView.setText(String.valueOf(golferBean
						.getReviewCount()));
			}
			progressBar.setVisibility(View.GONE);
		}

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			progressBar.setVisibility(View.VISIBLE);
		}
	}

}
